using System;
using System.Windows.Forms;
using FileSystemView.SelectedFsElements;
using HogoLogic.HgFileSystem;

namespace FileSystemView
{
	partial class DirectoryView : UserControl
	{
		readonly DirectoryTreeNodeVisualizer visualizer = new DirectoryTreeNodeVisualizer();
		
		public event EventHandler OnSelectedDirectoryChanged;
		
		public DirectoryView()
		{
			InitializeComponent();
		}
		
		public void Open(HgDirectoryInfo directoryInfo)
		{
			innerTreeView.Nodes.Clear();
			innerTreeView.Nodes.Add(visualizer.MakeTreeNode(directoryInfo));
		}

		public HgDirectoryInfo SelectedDirectory
		{
			get
			{
				return visualizer.GetDirectoryForTreeNode(
					innerTreeView.SelectedNode);
					
			}
		}

		public SelectedFsElement SelectedFsElement
		{
			get
			{
				if (innerTreeView.SelectedNode == null)
					return new SelectedNothing();
				return new SelectedDirectory(SelectedDirectory);
			}
		}

		public void UnselectFolder()
		{
			innerTreeView.SelectedNode = null;
		}

		public ContextMenuStrip InnerContextMenuStrip
		{
			get
			{
				return innerTreeView.ContextMenuStrip;
			}
			set
			{
				innerTreeView.ContextMenuStrip = value;
			}
		}
		
		private void innerTreeView_AfterSelect(object sender, TreeViewEventArgs e)
		{
			if (innerTreeView.SelectedNode != null)
				if (OnSelectedDirectoryChanged != null)
					OnSelectedDirectoryChanged(sender, new EventArgs());
		}
	}
}